#include <sys_config.h>
#include <types.h>
#include <basic_types.h>
#include <mediatypes.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>
#include <osal/osal.h>
#ifndef NEW_DEMO_FRAME
#include <api/libpub29/lib_hde.h>
#include <api/libpub29/lib_pub27.h>
#else
#include <api/libpub/lib_hde.h>
#endif

#include <api/libosd/osd_lib.h>

#include "osdobjs_def.h"
#include "images.id"
#include "string.id"
#include "osd_config.h"

#include "menus_root.h"
#include "win_com.h"
#include "win_com_popup.h"
#include "win_com_list.h"
#include "win_signalstatus.h"

#include "win_submenu.h"
#include "copper_common/system_data.h"
#ifdef THAILAND_TTC_SUPPORT
#include "ap_thailand_monitor.h"
#endif
#ifdef NETWORK_SUPPORT
#ifdef WIFI_SUPPORT
#include <api/libwifi/lib_wifi.h>
#endif
#endif
#ifdef PIP_PNG_GIF
#include <api/libmp/pe.h>
extern UINT8 pip_time;
#endif
#ifdef HILINK_SUPPORT
#include <api/libhilink/lib_hilink.h>
#endif
#if defined(SUPPORT_VMX_STD) || defined(SUPPORT_VMX)
#if 0
#define VMX_API_PRINTF		libc_printf
#else
#define VMX_API_PRINTF(...)	do{}while(0)
#endif
#endif

/*******************************************************************************
*	Objects definition
*******************************************************************************/

extern CONTAINER    g_win_mainmenu;
extern TEXT_FIELD    mainmenu_bg;

extern CONTAINER    mm_item_con1;
extern CONTAINER    mm_item_con2;
extern CONTAINER    mm_item_con3;
extern CONTAINER    mm_item_con4;
extern CONTAINER    mm_item_con5;
extern CONTAINER    mm_item_con6;
extern CONTAINER    mm_item_con7;
#ifndef DISABLE_USB
extern CONTAINER    mm_item_con6;
#endif

extern BITMAP		mm_item_bmp1;
extern BITMAP		mm_item_bmp2;
extern BITMAP		mm_item_bmp3;
extern BITMAP		mm_item_bmp4;
extern BITMAP		mm_item_bmp5;
extern BITMAP		mm_item_bmp6;
extern BITMAP		mm_item_bmp7;

extern TEXT_FIELD   mm_item_txt1;
extern TEXT_FIELD   mm_item_txt2;
extern TEXT_FIELD   mm_item_txt3;
extern TEXT_FIELD   mm_item_txt4;
extern TEXT_FIELD   mm_item_txt5;
extern TEXT_FIELD   mm_item_txt6;
#if defined(SUPPORT_CAS9) || defined(SUPPORT_CAS7)  || defined(SUPPORT_VMX) || defined(SUPPORT_VMX_STD)
    extern CONTAINER    mm_item_con7; 
    extern BITMAP       mm_item_bmp7; 
    extern TEXT_FIELD   mm_item_txt7; 
	#if defined(SUPPORT_CAS9) || defined(SUPPORT_CAS7)  
	BOOL ca_is_card_inited();
#endif
#endif
#ifdef _INVW_JUICE   
extern int inview_deferred_start;
#endif

//vicky20110524#1
#if (defined(USB_MP_SUPPORT) || defined(DVR_PVR_SUPPORT))
extern BOOL opened_by_hot_key;
#endif

static VACTION mm_item_con_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT mm_item_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static VACTION mm_con_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT mm_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

#define WIN_SH_IDX	  	WSTL_WIN_BODYLEFT_01_HD
#define WIN_HL_IDX	  	WIN_SH_IDX
#define WIN_SL_IDX	  	WIN_SH_IDX
#define WIN_GRY_IDX  	WIN_SH_IDX

#define MENU_BG_IDX	  	WSTL_WIN_MAINMENU_01_HD

#define CON_SH_IDX   WSTL_WIN_MAINMENU_01_BG_HD
#define CON_HL_IDX   CON_SH_IDX
#define CON_SL_IDX   CON_SH_IDX
#define CON_GRY_IDX  CON_SH_IDX

#define BMP_SH_IDX   WSTL_MIXBACK_BLACK_IDX_HD
#define BMP_HL_IDX   BMP_SH_IDX
#define BMP_SL_IDX   BMP_SH_IDX
#define BMP_GRY_IDX  BMP_SH_IDX

#define TXT_SH_IDX   0
#define TXT_HL_IDX   0
#define TXT_SL_IDX   0
#define TXT_GRY_IDX  0

#ifndef SD_UI

#if Maker_GUI_ON
#define	W_L     	Maker_GUI_MM_L//210 - 136
#define	W_T     	Maker_GUI_MM_T//138 - 40
#ifdef SUPPORT_CAS_A
#define	W_W	886
#else
#define	W_W			Maker_GUI_Frame_W
#endif
#define	W_H     	Maker_GUI_MM_H //568
#else
#define	W_L     	74//210 - 136
#define	W_T     	98//138 - 40
#ifdef SUPPORT_CAS_A
#define	W_W	886
#else
#define	W_W			866
#endif
#define	W_H     	488
#endif

#if Maker_GUI_ON
#define	MENUBG_L    W_L + 12
#define	MENUBG_W	W_W - 24
#else
#define	MENUBG_L     	(W_L+30)
//#define	MENUBG_T     	(W_T + 0)//(W_T + 12)
#define	MENUBG_W			120
#endif

#define CON_W		100+16
#if defined(SUPPORT_CAS9) || defined(SUPPORT_CAS7)  ||defined(SUPPORT_VMX) || defined(SUPPORT_VMX_STD)
    #define CON_H		70//65//70//80
    #define CON_GAP		12 // 3
    #define	MENUBG_T    (W_T - 5)
    #define	MENUBG_H     	460//450
#else
#if Maker_GUI_ON
//Gavim@menu
//#define CON_H		72//80
//#define CON_GAP		50
#define CON_H_TEMP 72
#define CON_H		85
#define CON_GAP		20
//----------
#define	MENUBG_T    (W_T + 5)
#define	MENUBG_H    90
#else
    #define CON_H		72//80
    #define CON_GAP		20
    #define	MENUBG_T    (W_T + 12)
    #define	MENUBG_H     	450
#endif
#endif

#define CON_L		(MENUBG_L+10)//(W_L + 30)//230

#if Maker_GUI_TEST
//#define CON_T		(MENUBG_T+8)
//Gavim@menu
#define CON_T		(MENUBG_T+0)
#else
#define CON_T		(MENUBG_T+0)//(MENUBG_T+10)//(W_T + 12)//150
#endif

#define BMP_L_OF	0
#define BMP_T_OF	0
#define BMP_W		CON_W
#if defined(SUPPORT_CAS9) || defined(SUPPORT_CAS7) ||defined(SUPPORT_VMX) || defined(SUPPORT_VMX_STD)
    #define BMP_H		58//68//72
#else
    #define BMP_H		CON_H//100//72//68//72
#endif

#else

#define	W_L     	17
#define	W_T        57
#define	W_W			570
#define	W_H     	370

#define	MENUBG_L     	(W_L+15)
#define	MENUBG_W		70

#define CON_W		64

#define CON_H		52//49//70//80
#define CON_GAP	        5//8// 1
#define	MENUBG_T    (W_T +5)
#define	MENUBG_H     	350//460//450

#define CON_L		(MENUBG_L+6)//(W_L + 30)//230
#define CON_T		(MENUBG_T+4)//(MENUBG_T+10)//(W_T + 12)//150

#define BMP_L_OF	0
#define BMP_T_OF	0
#define BMP_W		CON_W

#define BMP_H		48//58//68//72
#endif


#define TXT_L_OF  		(BMP_W + 20)
#define TXT_T_OF 		40
#define TXT_W			210
#define TXT_H			40

#define LDEF_MENUBG(root,varTxt,nxtObj,l,t,w,h,resID,str)		\
    DEF_TEXTFIELD(varTxt,&root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, MENU_BG_IDX,MENU_BG_IDX,MENU_BG_IDX,MENU_BG_IDX,   \
    NULL,NULL,  \
    C_ALIGN_CENTER | C_ALIGN_VCENTER, 0,0,resID,str)

#define LDEF_CON(root, varCon,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,conobj,focusID)		\
    DEF_CONTAINER(varCon,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, CON_SH_IDX,CON_HL_IDX,CON_SL_IDX,CON_GRY_IDX,   \
    mm_item_con_keymap,mm_item_con_callback,  \
    conobj, ID,1)
#define LDEF_CON_EX(root, varCon,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,conobj,focusID,DrawEffect)		\
    DEF_CONTAINER_EX(varCon,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, CON_SH_IDX,CON_HL_IDX,CON_SL_IDX,CON_GRY_IDX,   \
    mm_item_con_keymap,mm_item_con_callback,  \
    conobj, ID,1,DrawEffect)


#define LDEF_BMP(root,varbmp,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,bmpID)		\
    DEF_BITMAP(varbmp,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, BMP_SH_IDX,BMP_HL_IDX,BMP_SL_IDX,BMP_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_CENTER | C_ALIGN_VCENTER, 0,0,bmpID)
    
#define LDEF_TXT(root,varTxt,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,resID,str)		\
    DEF_TEXTFIELD(varTxt,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, TXT_SH_IDX,TXT_HL_IDX,TXT_SL_IDX,TXT_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_LEFT | C_ALIGN_VCENTER, 10,0,resID,str)
/*
#define LDEF_MM_ITEM(root,varCon,nxtObj,varbmp,varTxt,ID,IDu,IDd,l,t,w,h,bmpID,resID)	\
	LDEF_CON(&root,varCon,nxtObj,ID,ID,ID,IDu,IDd,l,t,w,h,&varbmp,1)	\
	LDEF_BMP(&varCon,varbmp,NULL,1,1,1,1,1,l + BMP_L_OF,t + BMP_T_OF,BMP_W,BMP_H,bmpID)	\
//	LDEF_TXT(&varCon,varTxt,NULL,0,0,0,0,0,l + TXT_L_OF, t + TXT_T_OF,TXT_W,TXT_H,resID,NULL)
*/

#define LDEF_MM_ITEM(root,varCon,nxtObj,varbmp,varTxt,ID,IDu,IDd,l,t,w,h,bmpID,resID,DrawEffect)	\
	LDEF_CON_EX(&root,varCon,nxtObj,ID,ID,ID,IDu,IDd,l,t,w,h,&varbmp,1,DrawEffect)	\
	LDEF_BMP(&varCon,varbmp,NULL,1,1,1,1,1,l + BMP_L_OF,t + BMP_T_OF,BMP_W,BMP_H,bmpID)	\

#if Maker_GUI_ON	/*Maker@20140918*/
#define AOV_W	CON_L+ (CON_W + CON_GAP)*4
#define AOV_L 	CON_L+ 20
#endif

#ifndef DISABLE_PVR_TMS
#if Maker_GUI_ON	/*Maker@20140918*/
/*LDEF_MENUBG(g_win_mainmenu,mainmenu_bg,&mm_item_con1,MENUBG_L,MENUBG_T,MENUBG_W,MENUBG_H,0,NULL)*/
LDEF_MENUBG(g_win_mainmenu,mainmenu_bg,&mm_item_con1,MENUBG_L,MENUBG_T,MENUBG_W,MENUBG_H,0,NULL)



LDEF_MM_ITEM(g_win_mainmenu,mm_item_con1, &mm_item_con2,mm_item_bmp1,mm_item_txt1,1,7,2,AOV_L+ (CON_H_TEMP + CON_GAP+ CON_GAP)*0, CON_T,CON_W,CON_H,	0,	0,DRAW_STYLE_SPHERE)

LDEF_MM_ITEM(g_win_mainmenu,mm_item_con2, &mm_item_con3,mm_item_bmp2,mm_item_txt2,2,1,3,AOV_L+ (CON_H_TEMP + CON_GAP+ CON_GAP)*1, CON_T,CON_W,CON_H,	0,	0,DRAW_STYLE_SPHERE)

LDEF_MM_ITEM(g_win_mainmenu,mm_item_con3, &mm_item_con4,mm_item_bmp3,mm_item_txt3,3,2,4,AOV_L+ (CON_H_TEMP + CON_GAP+ CON_GAP)*2, CON_T,CON_W,CON_H,	0,	0,DRAW_STYLE_SPHERE)

LDEF_MM_ITEM(g_win_mainmenu,mm_item_con4, &mm_item_con5,mm_item_bmp4,mm_item_txt4,4,3,5,AOV_L+ (CON_H_TEMP + CON_GAP+ CON_GAP)*3, CON_T,CON_W,CON_H,	0,	0,DRAW_STYLE_SPHERE)

LDEF_MM_ITEM(g_win_mainmenu,mm_item_con5,&mm_item_con6 ,mm_item_bmp5,mm_item_txt5,5,4,6,AOV_L+ (CON_H_TEMP + CON_GAP+ CON_GAP)*4, CON_T,CON_W,CON_H,	0,	0,DRAW_STYLE_SPHERE)//DRAW_STYLE_ONE)
//Gavim@YJ
LDEF_MM_ITEM(g_win_mainmenu,mm_item_con6, &mm_item_con7,mm_item_bmp6,mm_item_txt2,6,5,7,AOV_L+ (CON_H_TEMP + CON_GAP+ CON_GAP)*5, CON_T,CON_W,CON_H,	0,	0,DRAW_STYLE_SPHERE)

LDEF_MM_ITEM(g_win_mainmenu,mm_item_con7, NULL                 ,mm_item_bmp7,mm_item_txt2,7,6,1,AOV_L+ (CON_H_TEMP + CON_GAP+ CON_GAP)*6, CON_T,CON_W,CON_H,	0,	0,DRAW_STYLE_SPHERE)

//--------------------------------------------
#else  //Maker_GUI_ON

LDEF_MENUBG(g_win_mainmenu,mainmenu_bg,&mm_item_con1,MENUBG_L,MENUBG_T,MENUBG_W,MENUBG_H,0,NULL)

#if defined(SUPPORT_CAS9) || defined(SUPPORT_CAS7)  ||defined(SUPPORT_VMX) || defined(SUPPORT_VMX_STD)
LDEF_MM_ITEM(g_win_mainmenu,mm_item_con1, &mm_item_con2,mm_item_bmp1,mm_item_txt1,1,6,2,	\
				CON_L, CON_T + (CON_H + CON_GAP)*0,CON_W,CON_H,	0,	0,DRAW_STYLE_SPHERE)
#else
LDEF_MM_ITEM(g_win_mainmenu,mm_item_con1, &mm_item_con2,mm_item_bmp1,mm_item_txt1,1,5,2,	\
				CON_L, CON_T + (CON_H + CON_GAP)*0,CON_W,CON_H,	0,	0,DRAW_STYLE_SPHERE)
#endif
				
LDEF_MM_ITEM(g_win_mainmenu,mm_item_con2, &mm_item_con3,mm_item_bmp2,mm_item_txt2,2,1,3,	\
				CON_L, CON_T + (CON_H + CON_GAP)*1,CON_W,CON_H,	0,	0,DRAW_STYLE_FADE)

LDEF_MM_ITEM(g_win_mainmenu,mm_item_con3, &mm_item_con4,mm_item_bmp3,mm_item_txt3,3,2,4,	\
				CON_L, CON_T + (CON_H + CON_GAP)*2,CON_W,CON_H,	0,	0,DRAW_STYLE_ROTATE)
				
LDEF_MM_ITEM(g_win_mainmenu,mm_item_con4, &mm_item_con5,mm_item_bmp4,mm_item_txt4,4,3,5,	\
				CON_L, CON_T + (CON_H + CON_GAP)*3,CON_W,CON_H,	0,	0,DRAW_STYLE_SPHERE)

#if defined(SUPPORT_CAS9) || defined(SUPPORT_CAS7)  ||defined(SUPPORT_VMX) || defined(SUPPORT_VMX_STD)
LDEF_MM_ITEM(g_win_mainmenu,mm_item_con5,&mm_item_con6,mm_item_bmp5,mm_item_txt5,5,4,6,	\
				CON_L, CON_T + (CON_H + CON_GAP)*4,CON_W,CON_H,	0,	0,DRAW_STYLE_ZOOM)//DRAW_STYLE_ONE)

LDEF_MM_ITEM(g_win_mainmenu,mm_item_con6,NULL             ,mm_item_bmp6,mm_item_txt6,6,5,1,	\
				CON_L, CON_T + (CON_H + CON_GAP)*5,CON_W,CON_H,	0,	0,DRAW_STYLE_ZOOM)//DRAW_STYLE_ONE)

#else
LDEF_MM_ITEM(g_win_mainmenu,mm_item_con5,NULL             ,mm_item_bmp5,mm_item_txt5,5,4,1,	\
				CON_L, CON_T + (CON_H + CON_GAP)*4,CON_W,CON_H,	0,	0,DRAW_STYLE_ZOOM)//DRAW_STYLE_ONE)

#endif
#endif
#else  /* else of DISABLE_PVR_TMS */

LDEF_MENUBG(g_win_mainmenu,mainmenu_bg,&mm_item_con2,MENUBG_L,MENUBG_T,MENUBG_W,MENUBG_H,0,NULL)

#if defined(SUPPORT_CAS9) || defined(SUPPORT_CAS7) ||defined(SUPPORT_VMX) || defined(SUPPORT_VMX_STD)
LDEF_MM_ITEM(g_win_mainmenu,mm_item_con2, &mm_item_con3,mm_item_bmp2,mm_item_txt2,1,5,2,	\
				CON_L, CON_T + (CON_H + CON_GAP)*0,CON_W,CON_H,	0,	0,DRAW_STYLE_SPHERE)
#else
LDEF_MM_ITEM(g_win_mainmenu,mm_item_con2, &mm_item_con3,mm_item_bmp2,mm_item_txt2,1,4,2,	\
				CON_L, CON_T + (CON_H + CON_GAP)*0,CON_W,CON_H,	0,	0,DRAW_STYLE_SPHERE)
#endif
				
LDEF_MM_ITEM(g_win_mainmenu,mm_item_con3, &mm_item_con4,mm_item_bmp3,mm_item_txt3,2,1,3,	\
				CON_L, CON_T + (CON_H + CON_GAP)*1,CON_W,CON_H,	0,	0,DRAW_STYLE_FADE)

LDEF_MM_ITEM(g_win_mainmenu,mm_item_con4, &mm_item_con5,mm_item_bmp4,mm_item_txt4,3,2,4,	\
				CON_L, CON_T + (CON_H + CON_GAP)*2,CON_W,CON_H,	0,	0,DRAW_STYLE_ROTATE)
				
#if defined(SUPPORT_CAS9) || defined(SUPPORT_CAS7) ||defined(SUPPORT_VMX)  || defined(SUPPORT_VMX_STD)
LDEF_MM_ITEM(g_win_mainmenu,mm_item_con5,&mm_item_con6,mm_item_bmp5,mm_item_txt5,4,3,5,	\
				CON_L, CON_T + (CON_H + CON_GAP)*3,CON_W,CON_H,	0,	0,DRAW_STYLE_ZOOM)//DRAW_STYLE_ONE)

LDEF_MM_ITEM(g_win_mainmenu,mm_item_con6,NULL             ,mm_item_bmp6,mm_item_txt6,5,4,1,	\
				CON_L, CON_T + (CON_H + CON_GAP)*4,CON_W,CON_H,	0,	0,DRAW_STYLE_ZOOM)//DRAW_STYLE_ONE)

#else
LDEF_MM_ITEM(g_win_mainmenu,mm_item_con5,NULL             ,mm_item_bmp5,mm_item_txt5,4,3,1,	\
				CON_L, CON_T + (CON_H + CON_GAP)*3,CON_W,CON_H,	0,	0,DRAW_STYLE_ZOOM)//DRAW_STYLE_ONE)

#endif



#endif  /*end of DISABLE_PVR_TMS */

DEF_CONTAINER(g_win_mainmenu,NULL,NULL,C_ATTR_ACTIVE,0, \
    1,0,0,0,0, W_L,W_T,W_W,W_H, WIN_SH_IDX,WIN_HL_IDX,WIN_SL_IDX,WIN_GRY_IDX,   \
    mm_con_keymap,mm_con_callback,  \
    (POBJECT_HEAD)&mainmenu_bg, 1,0)

//    (POBJECT_HEAD)&mm_item_con1, 1,0)

/*******************************************************************************
*	Local functions & variables define
*******************************************************************************/

#define INSTALL_ID	    1
#define EDITCHAN_ID	    2

POBJECT_HEAD mm_menu_items[] = 
{
#ifndef DISABLE_PVR_TMS
	(POBJECT_HEAD)&mm_item_con1,
#endif
	(POBJECT_HEAD)&mm_item_con2,
	(POBJECT_HEAD)&mm_item_con3,
	(POBJECT_HEAD)&mm_item_con4,
	(POBJECT_HEAD)&mm_item_con5,
#if defined(SUPPORT_CAS9) || defined(SUPPORT_CAS7) ||defined(SUPPORT_VMX) || defined(SUPPORT_VMX_STD)
	(POBJECT_HEAD)&mm_item_con6,          //Conax CA container
#endif	
    (POBJECT_HEAD)&mm_item_con6,
    (POBJECT_HEAD)&mm_item_con7,    
};

BITMAP* mm_item_bmps[] = 
{
#ifndef DISABLE_PVR_TMS
	&mm_item_bmp1,
#endif	
	&mm_item_bmp2,
	&mm_item_bmp3,
	&mm_item_bmp4,
	&mm_item_bmp5,		
    &mm_item_bmp6,
    &mm_item_bmp7,    
/*    
#if defined(SUPPORT_CAS9) || defined(SUPPORT_CAS7) ||defined(SUPPORT_VMX) || defined(SUPPORT_VMX_STD)
    &mm_item_bmp6,
#endif           
*/
};
/*
UINT16 mm_item_bmp_ids[][3] =
{
    {IM_MEDIAPLAYER,	IM_MEDIAPLAYER_ON,		IM_MEDIAPLAYER_SELECT},
    {IM_CHANNEL,		IM_CHANNEL_ON,			IM_CHANNEL_SELECT},
    {IM_INSTALLATION,	IM_INSTALLATION_ON,		IM_INSTALLATION_SELECT},
    {IM_SYSTEM,			IM_SYSTEM_ON,			IM_SYSTEM_SELECT},
    {IM_TOOLS,			IM_TOOLS_ON,			IM_TOOLS_SELECT},
    {IM_CHANNEL,		IM_CHANNEL_ON,			IM_CHANNEL_SELECT},
    {IM_CHANNEL,		IM_CHANNEL_ON,			IM_CHANNEL_SELECT}, 
};
*/

//Gavim@menu 
UINT16 mm_item_bmp_ids[][3] =
{
    {IM_MEDIAPLAYER,   IM_MEDIAPLAYER_ON,		IM_MEDIAPLAYER_ON},	//USB
    {IM_CHANNEL,             IM_CHANNEL_ON,				IM_CHANNEL_ON},	//Channel
    {IM_TIMESET,               IM_TIMESET_ON,                    IM_TIMESET_ON},	//Time
    {IM_INSTALLATION,   IM_INSTALLATION_ON,		IM_INSTALLATION_ON}, //Installtion
    {IM_LANGUAGE,          IM_LANGUAGE_ON,               IM_LANGUAGE_ON}, 	// Language
    {IM_SYSTEM,                IM_SYSTEM_ON,                    IM_SYSTEM_ON},		// System
    {IM_TOOLS,                   IM_TOOLS_ON,						IM_TOOLS_ON}, 			//Tools
};
/*
UINT16 mm_item_str_ids[] =
{
#ifndef DISABLE_PVR_TMS
#if(((!defined SUPPORT_CAS9)&&(!defined FTA_ONLY)&&(!defined SUPPORT_VMX_STD)&&(!defined SUPPORT_VMX))|| (defined MEDIAPLAYER_SUPPORT))
	RS_COMMON_MEDIA_PLAYER,
#else
        //for 3281 32M no mediaplayer
        RS_RECORD_MANAGER,
#endif	
#endif
	RS_INFO_EDIT_CHANNEL,
	RS_INSTALLATION,
	RS_SYSTEM_SETUP,
	RS_TOOLS,
    RS_INFO_EDIT_CHANNEL,
    RS_INFO_EDIT_CHANNEL,    
};
*/
//Gavim@menu
UINT16 mm_item_str_ids[] =
{

#if(((!defined SUPPORT_CAS9)&&(!defined FTA_ONLY)&&(!defined SUPPORT_VMX_STD)&&(!defined SUPPORT_VMX))|| (defined MEDIAPLAYER_SUPPORT))
    RS_COMMON_MEDIA_PLAYER,
#else
    //for 3281 32M no mediaplayer
    RS_RECORD_MANAGER,
#endif
    RS_INFO_EDIT_CHANNEL,
    RS_SYSTEM_TIME,
    RS_INSTALLATION,
    RS_SYSTEM_LANGUAGE,   
    RS_SYSTEM_SETUP,
    RS_TOOLS, 
};
	
#define BMP_SH_ICON	0
#define BMP_HL_ICON	1
#define BMP_SL_ICON	 2

#define MENU_ITME_NUM	(sizeof(mm_menu_items)/sizeof(mm_menu_items[0]))

extern sub_menu_t* mainmenu_sub_menus[];
/*******************************************************************************
*	key mapping and event callback definition
*******************************************************************************/

//************************menu item: key mapping & event definition**************
static VACTION mm_item_con_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act;
	
	switch(key)
	{
#if Maker_GUI	/*Maker@20140918, Sub Menu*/
    case V_KEY_DOWN:
    case V_KEY_ENTER:
        act = VACT_ENTER;
        break;
    default:
        act = VACT_PASS;
#else
	case V_KEY_RIGHT:
	case V_KEY_ENTER:
		act = VACT_ENTER;
		break;		
	default:	
		act = VACT_PASS;
#endif
	}

	return act;
}

#if defined(SUPPORT_CAS9) || defined(SUPPORT_CAS7)
extern UINT8 Correct_card;
extern UINT16 card_msg_id;
extern UINT8 CA_menu_no_card_flag;
void cas_pop_start_timer2();
#endif

//Gavim@menu
extern date_time win_time_local_time;

static PRESULT mm_item_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	POBJECT_HEAD item;
	UINT8	id = OSD_GetObjID(pObj);
    UINT8   index = id - C_SUBMENU_ID_BASE;
	BITMAP* bmp;
	POBJECT_HEAD submenu;
	
    //Gavim@menu --------
	SYSTEM_DATA* p_sys_data;
	p_sys_data=sys_data_get();
	//-------------------------------
	   
	bmp = mm_item_bmps[index];
#if defined(SUPPORT_CAS9) || defined(SUPPORT_CAS7)
        UINT8 back_saved;
        struct smc_device *smc_dev;
	    smc_dev = (struct smc_device *)dev_get_by_id(HLD_DEV_TYPE_SMC, 0);
    #endif

	switch(event)
	{
		
	case EVN_FOCUS_PRE_GET:
		/* Clear normal show & set bmp highlight icon */			
		OSD_SetBitmapContent(bmp, mm_item_bmp_ids[index][BMP_HL_ICON]);		
		break;
	case EVN_FOCUS_POST_GET:
      //gavim@menu
       libc_printf("mm_item_con_callback ===EVN_FOCUS_POST_GET \n"  );
       libc_printf("==index %d \n" , index);
       
		wincom_open_title(pObj,mm_item_str_ids[index],0);		
		submenu_set_items(mainmenu_sub_menus[index]);
       // Gavim@manu 
       if( index == 2)
            {
		p_sys_data->gmt_select = p_sys_data->local_time.buseGMT;
		win_time_set_Region_string( p_sys_data->country);       	
		win_time_set_GMT_enable_string( p_sys_data->local_time.buseGMT );
		win_time_set_GMT_Offset_string(p_sys_data->local_time.GMToffset_count);
		get_local_time(&win_time_local_time);
		set_time_data();
		set_time_clock();
    			
		OSD_DrawObject((POBJECT_HEAD)&win_time_con, C_UPDATE_ALL);
		break;
      }
       if( index == 4)
       {
		win_lan_set_menu_lan_string(p_sys_data->lang.OSD_lang);
		win_lan_set_1st_audio_lan_string(p_sys_data->lang.Audio_lang_1);
		win_lan_set_2nd_audio_lan_string(p_sys_data->lang.Audio_lang_2);
		win_lan_set_subtitle_lan_string(p_sys_data->lang.sub_lang);
		win_lan_set_teletext_lan_string(p_sys_data->lang.ttx_lang);       	
       	OSD_DrawObject((POBJECT_HEAD)&win_lan_con, C_UPDATE_ALL);
       	break;
			}
       //========================================== 
        submenu_show();

		break;		
		
	case EVN_FOCUS_PRE_LOSE:
		/* Clear higlight show & set bmp normal icon */
		OSD_SetBitmapContent(bmp, mm_item_bmp_ids[index][BMP_SH_ICON]);
		break;
	
	case EVN_UNKNOWN_ACTION:
         libc_printf("====EVN_UNKNOWN_ACTION======= \n"  );
      
      //Gavim@menu    , Don't draw sub  menu item .
       if( index == 2)
       {				
  				if (OSD_ObjOpen(&win_time_con, 0xFFFFFFFF) != PROC_LEAVE)
					menu_stack_push(&win_time_con);				    	
       			break;
      }
       if( index == 4)
            {
  				if (OSD_ObjOpen(&win_lan_con, 0xFFFFFFFF) != PROC_LEAVE)
					menu_stack_push(&win_lan_con);    	
		        break;
			}
  
      
		submenu = (POBJECT_HEAD)&g_win_submenu;
		
		submenu_set_items(mainmenu_sub_menus[index]);	

		if(submenu_active(mainmenu_sub_menus[index]) )
		{
			//if(id == EDITCHAN_ID || id == INSTALL_ID)
			{
				if(sys_data_get_menu_lock())
				{
					if(!win_pwd_open(NULL,0))
						break;
				}
			}
			
			OSD_SetBitmapContent(bmp, mm_item_bmp_ids[index][BMP_SL_ICON]);
			//OSD_DrawObject((POBJECT_HEAD)bmp, C_UPDATE_ALL);
			OSD_DrawObject(pObj, C_UPDATE_ALL);

			/* Make OSD not flickering */
			OSD_TrackObject( submenu, C_DRAW_SIGN_EVN_FLG | C_UPDATE_FOCUS);
			menu_stack_push(submenu);
		}
		
		ret = PROC_LOOP;
		break;
			
	}


	return ret;
}

#if defined(SUPPORT_CAS9) || defined(SUPPORT_CAS7)
extern sub_menu_t sub_menu_conditional_access;
BOOL get_ca_menu_status()
{
    if(submenu_active(&sub_menu_conditional_access))
        return TRUE;
    else 
        return FALSE;
}
#endif


//************************window: key mapping & event definition**************
static VACTION mm_con_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act;
	
	switch(key)
	{
#if Maker_GUI	/*Maker@20140918, Main Menu*/
    case V_KEY_LEFT:
        act = VACT_CURSOR_UP;
        break;
    case V_KEY_RIGHT:
        act = VACT_CURSOR_DOWN;
        break;
    case V_KEY_EXIT:
    case V_KEY_MENU:
        act = VACT_CLOSE;
        break;
    default:
        act = VACT_PASS;
#else
	case V_KEY_UP:
		act = VACT_CURSOR_UP;
		break;
	case V_KEY_DOWN:
		act = VACT_CURSOR_DOWN;
		break;		
	case V_KEY_EXIT:
	case V_KEY_MENU:
		act = VACT_CLOSE;
		break;
	default:	
		act = VACT_PASS;
#endif
	}

	return act;
	
	
}

#ifdef _MHEG5_V20_ENABLE_
BOOL g_bExitFromCIbrowser = FALSE;
void set_menu_exit_from_ci_browser(BOOL b)
{
    g_bExitFromCIbrowser = b;
}

BOOL is_exit_from_ci_browser(void)
{
    return g_bExitFromCIbrowser;
}
#endif
    
extern UINT8 show_and_playchannel;
extern UINT8 play_chan_nim_busy;
void mm_enter_stop_mode(BOOL show_logo)
{
	POBJECT_HEAD menu;
	UINT8 av_flag;
	menu = menu_stack_get(0);
	epg_off();

#ifdef SAT2IP_CLIENT_SUPPORT
	if (api_cur_prog_is_sat2ip())
    {
		if (api_pvr_is_recording())
		{
			api_stop_record(0, 0);
			api_stop_record(0, 1);
		}
	
        win_satip_stop_play_channel();
        SatipClearTaskStatus();
    }
#endif
	
#ifdef CI_PLUS_SUPPORT
#ifdef _MHEG5_V20_ENABLE_ //MHEG5 enable, reserve 8MB
 //   ciplus_browser_exit();
#endif
#endif
#ifndef NEW_DEMO_FRAME
	si_monitor_off(0xFFFFFFFF);
#endif
	api_osd_mode_change(OSD_NO_SHOW);
		
	if(menu == NULL)
	{
			//dm_set_onoff(DM_NIMCHECK_OFF);
			//UIChChgStopProg(TRUE);
#ifdef DVR_PVR_SUPPORT			
		api_pvr_set_stop_play_attr(P_STOPPED_ONLY);
#endif
		api_stop_play(0);
#ifdef DVR_PVR_SUPPORT			
		api_pvr_tms_proc(FALSE);
		api_pvr_set_stop_play_attr(P_STOP_AND_REOPEN);
#endif
		if(show_logo)
			api_show_menu_logo();		
	}
	else
	{
		sys_data_save(1);
	}

	screen_back_state = SCREEN_BACK_MENU;
	play_chan_nim_busy = 0;
	SetChannelNimBusy(play_chan_nim_busy);

	av_flag = sys_data_get_cur_chan_mode();
	if(sys_data_get_sate_group_num(av_flag) > 0)
		key_pan_display("----", 4);
	else
		key_pan_display("noCH", 4);	
}

extern P_NODE playing_pnode;
void mm_leave_stop_mode()
{
	UINT8 group_idx;
	UINT16 channel;

	#if defined(SUPPORT_VMX_STD) ||defined(SUPPORT_VMX)		
		handle_osm_complement_in_ignore_window(FALSE);  
	#endif

#ifdef _MHEG5_V20_ENABLE_
    if(is_exit_from_ci_browser())
    {
#ifdef CI_PLUS_SUPPORT        
        ciplus_reenter_browser();
#endif
        set_menu_exit_from_ci_browser(FALSE);
        return;
    }
#endif

//	group_idx = sys_data_get_cur_group_index();
//	sys_data_change_group(group_idx);
	
#ifdef DVR_PVR_SUPPORT
#if 0 //def SAT2IP_SUPPORT //alan change for new spec.
    UINT16 rec_num = 0;
    ts_route_check_record_route_all(&rec_num);
    if(rec_num > 0)
#else    
	if(ap_pvr_set_state() == PVR_STATE_REC)
#endif	
    {				
#ifdef NEW_DEMO_FRAME
		if((sys_data_get_pip_support() == FALSE))// || (sys_data_get_pip_support() && (api_pip_check_pip_view() == TRUE)))
		{
			sys_data_change_normal_tp(playing_pnode);
		}
#endif
	}
	else
	{
		group_idx = sys_data_get_cur_group_index();
		sys_data_change_group(group_idx);
	}
#else
	group_idx = sys_data_get_cur_group_index();
	sys_data_change_group(group_idx);
#endif

	channel = sys_data_get_cur_group_cur_mode_channel();
	//dm_set_onoff(DM_NIMCHECK_ON);
	//ap_clear_all_message();	/* To clear signal message */
	{
		show_and_playchannel = 0;
#ifdef _INVW_JUICE
#else
		ap_send_msg(CTRL_MSG_SUBTYPE_CMD_ENTER_ROOT, (POBJECT_HEAD)&g_win_progname, TRUE);
#endif
        api_stop_play(0); //to call si_monitor_off for fixing bug 13806 --Michael 2008/2/18
		api_play_channel(channel, TRUE, TRUE,FALSE);

#ifdef SAT2IP_CLIENT_SUPPORT		
	if (api_cur_prog_is_sat2ip())
	{
	//	win_satip_set_prog_selected(channel);
		win_satip_play_channel(channel, FALSE, 0, 0);
	}
#endif


#ifdef _INVW_JUICE
	if (inview_deferred_start) {
  	  inview_init();
  	  inview_start();
           inview_deferred_start = 0;
	}

#endif

#ifdef CI_SUPPORT
        win_ci_force_send_ca_pmt();
#endif
	}	
#ifdef PARENTAL_SUPPORT
    clear_pre_ratinglock();
#endif
}

static void mm_osd_clear()
{
	OBJECT_HEAD mm_max_win;
	extern TEXT_FIELD menu_title_txt;
	extern CONTAINER  g_win_submenu;
	extern CONTAINER  g_win_mainmenu;

	MEMSET(&mm_max_win, 0, sizeof(mm_max_win));
	OSD_SetRect(&mm_max_win.frame, 
		menu_title_txt.head.frame.uLeft,
		menu_title_txt.head.frame.uTop,
		menu_title_txt.head.frame.uWidth,
		menu_title_txt.head.frame.uHeight + g_win_mainmenu.head.frame.uHeight);
	OSDDrv_ShowOnOff((HANDLE)g_osd_dev, OSDDRV_OFF);
	OSD_ClearObject((POBJECT_HEAD)&mm_max_win, 0);
	OSDDrv_ShowOnOff((HANDLE)g_osd_dev, OSDDRV_ON);

}

#if defined(SUPPORT_VMX_STD) || defined(SUPPORT_VMX)
UINT8 focus_mm_id = 0;
#endif
BOOL mainmenu_is_opening = FALSE;
static PRESULT mm_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT8	focusID = OSD_GetFocusID( pObj);
	UINT32 i;
	POBJECT_HEAD item;
	BITMAP* bmp;
	POBJECT_HEAD menu;
	UINT8 back_saved;
	UINT8 av_flag;
	UINT8 group_idx;
    UINT8 icon_index;
    //Martin@20150310
    SYSTEM_DATA* p_sys_data;
   	p_sys_data=sys_data_get();
	item = OSD_GetFocusObject(pObj);
    #if defined(SUPPORT_VMX_STD) || defined(SUPPORT_VMX)
    focus_mm_id = focusID;
#endif
	
	switch(event)
	{
	case EVN_PRE_OPEN:
   		#if defined(SUPPORT_VMX_STD) || defined(SUPPORT_VMX)
		handle_osm_complement_in_ignore_window(TRUE);  	
     	VMX_API_PRINTF("%s-In MM\n",__FUNCTION__); 
     	#endif
        mainmenu_is_opening = TRUE ;

        if(GetPauseState())
        {
            SetPauseOnOff(TRUE);
        }
#ifdef THAILAND_TTC_SUPPORT
        ap_thai_nit_monitor_stop();
        ap_thai_sdt_monitor_stop();
#endif

#ifdef PIP_PNG_GIF
	    //image_abort();
        ad_pic_gif_close();
	    OSD_ClearScreen();
        pip_time = -1;
#endif        

#ifdef CI_PLUS_SUPPORT
#ifdef _MHEG5_V20_ENABLE_
		//Generic_Browser debugging
		//===========================
		ciplus_browser_exit();
#endif
#endif
     
  #if defined(SUPPORT_CAS9) || defined(SUPPORT_CAS7)
        	/*clean msg*/
        	//clean_mmi_msg(1, TRUE);
        	clean_mmi_msg(3, TRUE);
        	clean_mmi_msg(4, TRUE);
        	clean_mmi_msg(6, TRUE);
        	if(get_mmi_showed()==1||get_mmi_showed()==6)
        	{
        		//win_mmipopup_close(1);
		#if defined(SUPPORT_CAS7)//SUPPORT_CAS7 alone
			win_mmipopup_close(1);
		#else
			win_pop_msg_close(1);
		#endif	
        		//win_fingerpop_close();
        	}
            win_fingerpop_close();
        	if(get_mmi_showed()!=5)
        		set_mmi_showed(10);

		extern UINT8 rec_manager_show_flag ;
		rec_manager_show_flag = FALSE;//exit rec_manager and return live.
        #endif
		
		//vicky20110524#1
		#if (defined(USB_MP_SUPPORT) || defined(DVR_PVR_SUPPORT))
		opened_by_hot_key=FALSE;
		#endif	
		
        //system_state = SYS_STATE_NORMAL;/*should reset the system_state<Doy.Dong,2011-7-9>*/
        api_set_system_state(SYS_STATE_NORMAL);
		screen_back_state = SCREEN_BACK_MENU;
        if(api_pvr_get_back2menu_flag())   //fixed bug39665:enter in mainmenu when playback,than duration record,when end,should not enter in pvr manager
            api_pvr_set_back2menu_flag(0);
        
#ifndef DVR_PVR_SUPPORT
		mm_menu_items[0]->bUpID = MENU_ITME_NUM;
		mm_menu_items[MENU_ITME_NUM-1]->bDownID = 1;		
		mm_menu_items[MENU_ITME_NUM-1]->pNext = NULL;
#endif
		/* Set each item to noraml position and normal bmp icon */
		for(i=0;i<MENU_ITME_NUM;i++)
		{
			bmp = mm_item_bmps[i];
			OSD_SetBitmapContent(bmp, mm_item_bmp_ids[i][BMP_SH_ICON]);
		}

		/* Set focus item highlight position and highlight bmp icon */
		item = OSD_GetFocusObject(pObj);
		bmp = mm_item_bmps[focusID - 1];
		OSD_SetBitmapContent(bmp, mm_item_bmp_ids[focusID - 1][BMP_HL_ICON]);
		mm_enter_stop_mode(TRUE);

#if (CC_ON==1)
		cc_vbi_show_on(FALSE);
#endif
		wincom_open_title(pObj,mm_item_str_ids[focusID - C_SUBMENU_ID_BASE],0);
		sys_data_set_cur_satidx((UINT16) (~0));//restore sat_idx
		break;		
	case EVN_POST_OPEN:
		//Gavim@menu
		 libc_printf("===mm_con_callback  EVN_POST_OPEN=== \n" );
		icon_index = focusID - C_SUBMENU_ID_BASE;
		if(icon_index ==2)
		{
			submenu_set_items(mainmenu_sub_menus[icon_index]);// Draw title
			/*Martin@20150310*/
			win_time_set_GMT_Offset_string(p_sys_data->local_time.GMToffset_count);
			get_local_time(&win_time_local_time);
			set_time_data();
			set_time_clock();
			//----End Martin
		     OSD_DrawObject((POBJECT_HEAD)&win_time_con, C_UPDATE_ALL);// Draw time window
        		break;			
		}
		if(icon_index ==4)
		{
			submenu_set_items(mainmenu_sub_menus[icon_index]);// Draw title
		     OSD_DrawObject((POBJECT_HEAD)&win_lan_con, C_UPDATE_ALL);// Draw  language window
        		break;			
		}		

		if(param2 != 0xFFFFFFFF)	/* 0xFFFFFFFF means open from the stack  */
		{
			submenu_set_items(mainmenu_sub_menus[focusID - C_SUBMENU_ID_BASE]);
			submenu_show();
		}
        
        mainmenu_is_opening = FALSE;
		break;
		
	case EVN_PRE_CLOSE:
#ifdef PIP_PNG_GIF
	    //image_abort();
        ad_pic_gif_close();
	    //OSD_ClearScreen();
        pip_time = 0;
#endif     
		sys_data_check_channel_groups();
        av_flag = sys_data_get_cur_chan_mode();
        if( sys_data_get_group_num() == 0 )
            sys_data_set_cur_chan_mode(av_flag==TV_CHAN? RADIO_CHAN : TV_CHAN);        
		if( sys_data_get_group_num() == 0 )
		{
		    sys_data_set_cur_chan_mode(av_flag);
			win_compopup_init(WIN_POPUP_TYPE_SMSG);
			win_compopup_set_msg(NULL,NULL, RS_MSG_NO_CHANNELS);
			win_compopup_open_ext(&back_saved);
			osal_task_sleep(1000);
			win_compopup_smsg_restoreback();
			ret = PROC_LOOP;
		}
		else
		{
			/* Make OSD not flickering */
			*((UINT32*)param2) &= ~C_CLOSE_CLRBACK_FLG;	
		}
		break;

	case EVN_POST_CLOSE:
#if defined(SUPPORT_CAS9) || defined(SUPPORT_CAS7)
            restore_ca_msg_when_exit_win();
        #endif
		
#ifdef PIP_PNG_GIF
	    //image_abort();
        ad_pic_gif_close();
	    //OSD_ClearScreen();
        pip_time = 0;
#endif        
		mm_osd_clear();
		mm_leave_stop_mode();
#ifdef _INVW_JUICE   //v0.1.4
      INVIEW_RefreshServices(TRUE, 1);
#endif
#if (CC_ON==1)
		cc_vbi_show_on(TRUE);
#endif
		
		break;		
	case EVN_MSG_GOT:
		if(	param1 == CTRL_MSG_SUBTYPE_CMD_STO && param2 == USB_STATUS_OVER)
        {
			//storage_dev_mount_hint(1);

			//Gavim@menu  , Don't  redraw menu 
			icon_index = focusID - C_SUBMENU_ID_BASE;
			if(icon_index ==2)// Time
				break;			
			if(icon_index ==4)// Language
				break;			
			
 			submenu_set_items(mainmenu_sub_menus[focusID - C_SUBMENU_ID_BASE]);
			submenu_show();
		}
		break;
	default:
		break;
	}

	return ret;
}

#ifdef DVR_PVR_SUPPORT
BOOL win_mainmenu_in_pvr_submenu(void)
{
    return (OSD_GetContainerFocus(&g_win_mainmenu) == INSTALL_ID) || (OSD_GetContainerFocus(&g_win_mainmenu) == EDITCHAN_ID);
}
#endif

// mm_foucs: begin from 0
// sub_mm_foucs: begin from 0
BOOL win_mainmenu_set_sub_foucs(UINT8 mm_focus, UINT8 sub_mm_focus)
{
	UINT8 i;	

    OSD_SetContainerFocus(&g_win_mainmenu, mm_focus+1);
    win_submenu_set_focus(mm_focus, sub_mm_focus);
	/* Set each item to noraml position and normal bmp icon */
	for(i=0;i<MENU_ITME_NUM;i++)
	{
		if(i == mm_focus)			
			OSD_SetBitmapContent(mm_item_bmps[i], mm_item_bmp_ids[i][BMP_SL_ICON]);
		else
			OSD_SetBitmapContent(mm_item_bmps[i], mm_item_bmp_ids[i][BMP_SH_ICON]);
	}
	
	submenu_set_items(mainmenu_sub_menus[mm_focus]);

}

#ifdef USB_MP_SUPPORT
extern sub_menu_t sub_menu_mediaplayer;
BOOL win_mainmenu_set_focus_to_usb(void)
{
	UINT8 i;	
	UINT8 mm_index;

        mm_index = MEDIAPLAYER_ID - C_SUBMENU_ID_BASE;
	return win_mainmenu_set_sub_foucs(mm_index, sub_menu_mediaplayer.list_sel);

}
#endif

#if defined(SUPPORT_VMX_STD) || defined(SUPPORT_VMX)
BOOL win_mainmenu_set_focus_to_ota_upgrade(void)
{
	UINT8 i;	
	UINT8 mm_index;

	mm_index = TOOLS_ID - C_SUBMENU_ID_BASE;
	return win_mainmenu_set_sub_foucs(mm_index, TOOLS_OTAUPG_ID-C_SUBMENU_ID_BASE);
}
void sm_exit_to_mm() 
{
	//libc_printf("sm_exit_to_mm \n");
	//POBJECT_HEAD   newMenu;
	while(menu_stack_get_top() != (POBJECT_HEAD)&g_win_mainmenu) {
		menu_stack_pop();
		if(NULL==menu_stack_get_top())
		{
			break;
		}
	}
	OSD_ObjOpen((POBJECT_HEAD)&g_win_mainmenu, MENU_OPEN_TYPE_STACK);
	//OSD_SetContainerFocus(&g_win_submenu, -1);
	//OSD_DrawObject((POBJECT_HEAD)&g_win_submenu, C_DRAW_SIGN_EVN_FLG | C_UPDATE_FOCUS);
}
#endif

